package com.rzdata.poct.web.controller.business;

import com.rzdata.poct.common.annotation.Log;
import com.rzdata.poct.common.annotation.RepeatSubmit;
import com.rzdata.poct.common.core.controller.BaseController;
import com.rzdata.poct.common.core.domain.AjaxResult;
import com.rzdata.poct.common.core.page.TableDataInfo;
import com.rzdata.poct.common.core.validate.AddGroup;
import com.rzdata.poct.common.core.validate.EditGroup;
import com.rzdata.poct.common.core.validate.QueryGroup;
import com.rzdata.poct.common.enums.BusinessType;
import com.rzdata.poct.common.utils.poi.ExcelUtil;
import com.rzdata.poct.system.domain.business.bo.PoctInstrumentStatusBo;
import com.rzdata.poct.system.domain.business.vo.PoctInstrumentStatusVo;
import com.rzdata.poct.system.service.IPoctInstrumentStatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2021-09-09
 */
@Validated
@Api(value = "设备状态控制器", tags = {"设备状态管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/instrumentStatus")
public class PoctInstrumentStatusController extends BaseController {

    private final IPoctInstrumentStatusService iPoctInstrumentStatusService;

    /**
     * 查询【请填写功能名称】列表
     */
    @ApiOperation("查询设备状态列表")
    @PreAuthorize("@ss.hasPermi('system:instrumentStatus:list')")
    @GetMapping("/list")
    public TableDataInfo<PoctInstrumentStatusVo> list(@Validated(QueryGroup.class) PoctInstrumentStatusBo bo) {
        return iPoctInstrumentStatusService.queryPageList(bo);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation("导出设备状态列表")
    @PreAuthorize("@ss.hasPermi('system:instrumentStatus:export')")
    @Log(title = "【导出设备状态列表】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(@Validated PoctInstrumentStatusBo bo, HttpServletResponse response) {
        List<PoctInstrumentStatusVo> list = iPoctInstrumentStatusService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", PoctInstrumentStatusVo.class, response);
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @ApiOperation("获取设备状态详细信息")
    @PreAuthorize("@ss.hasPermi('system:instrumentStatus:query')")
    @GetMapping("/{id}")
    public AjaxResult<PoctInstrumentStatusVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iPoctInstrumentStatusService.queryById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @ApiOperation("新增设备状态")
    @PreAuthorize("@ss.hasPermi('system:instrumentStatus:add')")
    @Log(title = "【新增设备状态】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public AjaxResult<Void> add(@Validated(AddGroup.class) @RequestBody PoctInstrumentStatusBo bo) {
        return toAjax(iPoctInstrumentStatusService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @ApiOperation("修改设备状态")
    @PreAuthorize("@ss.hasPermi('system:instrumentStatus:edit')")
    @Log(title = "【修改设备状态】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public AjaxResult<Void> edit(@Validated(EditGroup.class) @RequestBody PoctInstrumentStatusBo bo) {
        return toAjax(iPoctInstrumentStatusService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除【请填写功能名称】
     */
    @ApiOperation("删除设备状态")
    @PreAuthorize("@ss.hasPermi('system:instrumentStatus:remove')")
    @Log(title = "【删除设备状态】" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPoctInstrumentStatusService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
